import QtQuick 2.0
import CustomComponents 1.0
import QtQuick.LocalStorage 2.0 as Sql
import "../Keyboard"
import "../"
import "../content"
Rectangle{
    id:window
    height: parent.height
    width: parent.width
  //  anchors.fill: parent
    signal enter(string order,string name)
    property alias  listview: list
    color: "black"
    Component.onCompleted: {
        db.makeRecordListTopic(list.alist);
    }

//    Db_connect{
//        id:db
//    }
    Db_BMSA{
        id:db
    }

    ListTopic{
        id:list
    }
    Rectangle{
        id:but
        anchors.right: parent.right
        color:"#00000000"
        width: parent.width *0.4
        height: parent.height*0.75
        anchors.verticalCenter:  parent.verticalCenter
        Button{
            id:b1
            label: "Add Topic"
            anchors.top:parent.top
            anchors.topMargin: 50
            anchors.horizontalCenter:parent.horizontalCenter
            onClicked: {
                //  list.addlist("2","sd","adf");
                //db.loadRecordList();


                addtopic.visible=true
                addtopic.enabled=true
                list.enabled=false
                but.enabled=false

            }
        }
        Button{
            id:b2
            label: "Edit Topic"
            anchors.top:b1.bottom
            anchors.horizontalCenter:parent.horizontalCenter
            onClicked: {
                // Sql.LocalStorage.openDatabaseSync("MyAppName", "1.0", "StorageDatabase", 100000);

                db.initialize();
                // Sets a value in the database

               // db.setSetting(list.alist.count+1,"myValue");
                // Sets the textDisplay element's text to the value we just set
                list.addlist(list.alist.count+1,db.getSetting("mySetting"),"adf");

            }
        }
        Button{
            id:b3
            label: "Export Data"
            anchors.top:b2.bottom
            anchors.horizontalCenter:parent.horizontalCenter
            onClicked: {
               // db.makeRecordListTopic(list.alist);
                expdata.visible=true
                expdata.enabled=true
                list.enabled=false
                but.enabled=false
            }
        }
        Button{
            label: "select"
            anchors.top:b3.bottom
            anchors.horizontalCenter:parent.horizontalCenter
            onClicked: {

                enter(list.alist.get(list.index).order,list.alist.get(list.index).Type);
                console.debug(list.alist.get(list.index).order);
            }
        }
    }
    AddTopic {
        id:addtopic
        anchors.fill: parent
        visible: false
        enabled: false
        onEnter: {
             db.initialize();
            db.setTopic(addtopic.topicname.toString(),currentDateAndTime);
            list.enabled=true
            but.enabled=true
            addtopic.visible=false
            addtopic.enabled=false
            db.makeRecordListTopic(list.alist);


        }
    }
    Export{
        id:expdata
        visible: false
        enabled: false
        onEnter: {
            list.enabled=true
            but.enabled=true
            expdata.visible=false
            expdata.enabled=false
        }
    }

}

